define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'house/house/index' + location.search,
                    // add_url: 'house/house/add',
                    edit_url: 'house/house/edit',
                    del_url: 'house/house/del',
                    multi_url: 'house/house/multi',
                    import_url: 'house/house/import',
                    table: 'house',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'),operate:false},
                        // {field: 'room_id', title: __('Room_id')},
                        {field: 'user_id', title: __('User_id'), visible:false, addClass: "selectpage", extend: "data-source='user/user/index' data-field='username'"},
                        {field: 'user.username', title: __('用户名'),operate:false},
                        {field: 'name', title: __('Name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'type', title: __('Type'),visible:false,switchable:false,searchList: Config.typeList},
                        {field: 'type_text', title: __('Type'),operate:false},
                        {field: 'community', title: __('Community'),visible:false,switchable:false,searchList:Config.communityList},
                        {field: 'community_text', title: __('Community'),operate:false},
                        // {field: 'street_text', title: __('Street'), operate: false},
                        {field: 'rent', title: __('Rent'), operate:'BETWEEN'},
                        {field: 'area', title: __('Area'), operate:'BETWEEN'},
                        {field: 'house_type_text', title: __('House_type'), operate: false},
                        {field: 'floor', title: __('Floor'), operate:'BETWEEN'},
                        {field: 'payment_type_text', title: __('Payment_type'), operate: false},
                        {field: 'face', title: __('Face')},
                        //{field: 'check_in', title: __('Check_in'), operate: false},
                        //{field: 'rent_type_text', title: __('Rent_type'), operate: false},
                        {field: 'decoration_text', title: __('Decoration'), operate: false},
                        // {field: 'deposit', title: __('Deposit'), operate:'BETWEEN'},
                        {field: 'water_rate', title: __('Water_rate'), operate:'BETWEEN'},
                        {field: 'power_rate', title: __('Power_rate'), operate:'BETWEEN'},
                        // {field: 'facilities', title: __('Facilities'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'address', title: __('Address'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'notice', title: __('Notice'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'status', title: __('Status'), searchList: Config.statusList, formatter: Table.api.formatter.status},
                        {field: 'is_ax', title: __('Is_ax'),searchList:Config.searchList, formatter: Table.api.formatter.toggle},
                        {field: 'is_recommend', title: __('Is_recommend'),searchList:Config.searchList, formatter: Table.api.formatter.toggle},
                        // {field: 'tags', title: __('Tags'), operate: 'LIKE', formatter: Table.api.formatter.flag},
                        {field: 'visit_num', title: __('Visit_num'), operate: false},
                        {field: 'is_finish', title: __('is_finish'),searchList:Config.searchList, formatter: Table.api.formatter.status},
                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {

            $('#c-street').data('params',function () {
                return {custom:{cid:3,pid:$('#c-community').val()}};
            });
            $(document).on('change','#c-community',function () {
                $('#c-street').selectPageClear();
            });
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
